#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Yield/ZeroYieldStructure.h>
#pragma unmanaged 
#include <ql\termstructures\yield\piecewisezerospreadedtermstructure.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Yield {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IPiecewiseZeroSpreadedTermStructure
	public ref class CPiecewiseZeroSpreadedTermStructure  : 
            public CZeroYieldStructure,
            public Cephei::QL::Termstructures::Yield::IPiecewiseZeroSpreadedTermStructure
	{
	protected: 
		boost::shared_ptr<QuantLib::PiecewiseZeroSpreadedTermStructure>* _ppPiecewiseZeroSpreadedTermStructure;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::PiecewiseZeroSpreadedTermStructure>* _phPiecewiseZeroSpreadedTermStructure;
#endif
		Object^ _PiecewiseZeroSpreadedTermStructureOwner;     // reference to object that manages the storage for this object
	internal:
		CPiecewiseZeroSpreadedTermStructure (Cephei::QL::Termstructures::IYieldTermStructure^ prm1, Cephei::Core::IVector<Cephei::QL::IQuote^>^ spreads, Cephei::Core::IVector<DateTime>^ dates, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ comp, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ freq, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
        CPiecewiseZeroSpreadedTermStructure (boost::shared_ptr<QuantLib::PiecewiseZeroSpreadedTermStructure>& childNative, Object^ owner);
        CPiecewiseZeroSpreadedTermStructure (QuantLib::PiecewiseZeroSpreadedTermStructure& childNative, Object^ owner);
        CPiecewiseZeroSpreadedTermStructure (CPiecewiseZeroSpreadedTermStructure^ copy);
        CPiecewiseZeroSpreadedTermStructure (PLATFORM::Type^ t);
#ifdef STRUCT
        CPiecewiseZeroSpreadedTermStructure (QuantLib::PiecewiseZeroSpreadedTermStructure childNative);
#endif       
#ifdef HANDLE
		CPiecewiseZeroSpreadedTermStructure (QuantLib::Handle<QuantLib::PiecewiseZeroSpreadedTermStructure>& childNative, Object^ owner);
		CPiecewiseZeroSpreadedTermStructure (QuantLib::Handle<QuantLib::PiecewiseZeroSpreadedTermStructure> childNative);
#endif
		virtual ~CPiecewiseZeroSpreadedTermStructure ();
		!CPiecewiseZeroSpreadedTermStructure ();

	internal:
		QuantLib::PiecewiseZeroSpreadedTermStructure& GetReference ();
		boost::shared_ptr<QuantLib::PiecewiseZeroSpreadedTermStructure>& GetShared ();
		QuantLib::PiecewiseZeroSpreadedTermStructure* GetPointer ();
        void SetPiecewiseZeroSpreadedTermStructure (boost::shared_ptr<QuantLib::PiecewiseZeroSpreadedTermStructure> native)
        {
            if (_ppPiecewiseZeroSpreadedTermStructure != NULL)
                delete _ppPiecewiseZeroSpreadedTermStructure;
            _ppPiecewiseZeroSpreadedTermStructure = new boost::shared_ptr<QuantLib::PiecewiseZeroSpreadedTermStructure> (native);
            SetZeroYieldStructure (boost::dynamic_pointer_cast<QuantLib::ZeroYieldStructure> (*_ppPiecewiseZeroSpreadedTermStructure));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::PiecewiseZeroSpreadedTermStructure>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Times::ICalendar^ Calendar 
        {
		    virtual Cephei::QL::Times::ICalendar^ get () ;
        }
        property Cephei::QL::Times::IDayCounter^ DayCounter 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property DateTime MaxDate 
        {
		    virtual DateTime get () ;
        }
        property DateTime ReferenceDate 
        {
		    virtual DateTime get () ;
        }
        property UInt32 SettlementDays 
        {
		    virtual UInt32 get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Termstructures::Yield::IPiecewiseZeroSpreadedTermStructure^>::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IPiecewiseZeroSpreadedTermStructure::typeid)]
	[FactoryFor(Cephei::QL::Termstructures::Yield::IPiecewiseZeroSpreadedTermStructure_Factory::typeid)]
	public ref class CPiecewiseZeroSpreadedTermStructure_Factory sealed : public IPiecewiseZeroSpreadedTermStructure_Factory
	{
	public:
        virtual IPiecewiseZeroSpreadedTermStructure^ Create (Cephei::QL::Termstructures::IYieldTermStructure^ prm1, Cephei::Core::IVector<Cephei::QL::IQuote^>^ spreads, Cephei::Core::IVector<DateTime>^ dates, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ comp, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ freq, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Yield */}
